<style src="../../style/contentTable.css" scoped></style>
<template>
  <div class="containerTable">
    <!--表5蔬菜生产经营实体表T_VegProsecution-->
    <Row class="divSearch">
            <Col span="24" class="col-margin">
                <!--根据需求删除不不要查询条件-->
                填报年度:
                <Select v-model="searchModel.FillInYear" placeholder="全部" style="width: 200px" @on-change="getPageData()">
                    <Option value="">全部</Option>
                    <Option :value="item.DictValue" v-for="item in CreateYearList" :key="item.DictValue">{{item.DictText}}</Option>
                </Select>
                <!--填报季度:
                <Select v-model="searchModel.TimesType" placeholder="全部" style="width: 100px" @on-change="GetData()">
                    <Option value="">全部</Option>
                    <Option :value="item.DictValue" v-for="item in CycleList" :key="item.DictValue">{{item.DictText}}</Option>
                </Select>-->
                <Button icon="ios-search" type="ghost" @click="GetData()">查询</Button>
                <Button icon="ios-search" type="primary" @click="TmpDown()" style="float:right;margin-right:5px">模板下载</Button>
            </Col>
        </Row>
        <Row>
            <Col span="24" class="col-margin" v-show="isTime()">
            <Table size="small" @on-select="selectSingel" @on-select-all="selectAll" :height="clientHeight" border :context="ctx" :columns="columnsList" :data="datas.rows" no-data-text='暂无数据...'></Table>
            </Col>
            <Col class="col-margin" v-show="!isTime()">
              <Alert class="AlterWarm">不在填报时间内，无法填报！</Alert>
            </Col>
        </Row>
        <!-- <Row>
            <Col span="24">
            <Page class="page-style" :total="datas.total" placement="top" @on-change="getPageNumber" :page-size="searchModel.PageSize" :page-size-opts='pageSizeOpts' show-sizer @on-page-size-change="getPageSize" show-total show-elevator></Page>
            </Col>
        </Row> -->
        <Modal v-model="showType" :mask-closable="false" :closable="true" width="1200">
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">生产情况调查表</span>
            </p>
            <p slot="close">
                <Icon type="close-circled" color="red" size=25></Icon>
            </p>
            <Tabs type="card" @on-click="getTab">
                <Tab-pane v-for="tabPane in TabTitleList" :label="tabPane.SortName" :name="tabPane.SortCode" :key="tabPane.SortName">
                    <div style="height:450px;overflow-y:auto">
                        <table class="reptable">
                            <tr>
                                <th rowspan="2" width="160px">品种</th>
                                <th rowspan="2">全年累计面积</th>
                                <th colspan="4">其中</th>
                                <th rowspan="2">全年累计产量</th>
                                <!--<th rowspan="2">全年平均价格</th>-->
                            </tr>
                            <tr>
                                <th>当年新植果园</th>
                                <th>5年以下果园</th>
                                <th>5-20年果园</th>
                                <th>20年以上果园面积</th>
                            </tr>
                            <tr v-for="item in tabPane.list">
                                <td v-if="item.ItemName==item.SortSonName" style="padding-right: 5px;width:200px;text-align:right;">
                                    <b>{{item.ItemName}}</b>
                                </td>
                                <td v-if="item.ItemName!=item.SortSonName" style="padding-right: 5px;width:200px;text-align:right;">
                                    <b>{{item.SortSonName}}</b>
                                    <span style="color:green" v-if="item.ItemName==null">{{item.ItemName}}</span>
                                    <span v-else><b>{{item.ItemName}}</b></span>
                                    </td>
                                <td>
                                    <Input v-model="item.GrandArea"></Input>
                                </td>
                                <td>
                                    <Input v-model="item.NewArea"></Input>
                                </td>
                                <td>
                                    <Input v-model="item.FOrchard"></Input>
                                </td>
                                <td>
                                    <Input v-model="item.FTOrchard"></Input>
                                </td>
                                <td>
                                    <Input v-model="item.TOrchard"></Input>
                                </td>
                                <td>
                                    <Input v-model="item.CumYield"></Input>
                                </td>
                               <!-- <td>
                                    <Input v-model="item.AvgPrice"></Input>
                                </td>-->
                            </tr>
                        </table>
                    </div>
    
                    <div style="text-align:right;padding-top:10px">
                        <Button type="primary" @click="save()">保存</Button>
                        <Button type="ghost" @click="cancel()" style="margin-left: 5px">取消</Button>
                    </div>
                </Tab-pane>
            </Tabs>
            <div slot="footer">
                <Alert style="margin-top:5px;text-align:left" banner type="error">
                    填报说明: 1.全省范围内从乡（镇）推广站起，逐级全面统计，由州（市）汇总后上报。
                    <br/> 2.统计面积中不含育苗面积。
                    <br/>幼年：树龄5年以下果园面积；盛果期：树龄5-20年果园面积；老果园：树龄20年以上果园面积
                    <br/>3. 水果分四个树龄阶段统计，各不互相包含；其中5年以下的，则不包含新植面积
                    <br/>4.一年生水果不分树龄统计。
                    <span slot="desc">
                    </span>
                </Alert>
            </div>
        </Modal>        
        <Modal v-model="ViewShow" :mask-closable="false" width="1300" :styles="{top: '20px'}">
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">主要水果生产情况年度面积产量表</span>
            </p>
            <p slot="close">
                <Icon type="close-circled" color="red" size=25></Icon>
            </p>
            <Form ref="DataForm" :model="{list}" style="width:1232px">            
              <table class="ContentTable">
              <caption>                  
                  <label style="float:right">单位：
                      <span>亩、吨、吨/亩</span>                
                  </label>
              </caption>
                <thead>
                <tr>                  
                    <th  rowspan="2" >品种</th>
                    <th rowspan="2">全年累计面积</th>
                    <th rowspan="2" >全年累计产量</th>
                    <th rowspan="2" >平均亩产</th>
                    <th colspan="4" >其中</th>  
                    <th  rowspan="2" >备注</th>                                      
                </tr>
                <tr>
                    <th >当年新植果园面积</th>
                    <th >树龄5年以下果园面积</th>
                    <th >树龄5-20年果园面积</th>
                    <th >树龄20年以上果园面积</th>
                    </tr>
                </thead>              
              <tbody>
                  <tr v-for="(item,index) in list" :key="index" v-if="item.VarietyCode!='sum'">
                    <td v-if="item.ParentCode" style="text-align:right;">{{item.Variety}}</td>
                    <td v-else style="font-weight:bold;">{{item.Variety}}</td>
                    <td >
                      <Form-item :prop="'list.' + index + '.GrandArea'" :rules="{validator: validrule, trigger: 'blur'}">
                        <Input v-model="item.GrandArea"></Input>                            
                      </Form-item>
                    </td>
                    <td >
                      <Form-item :prop="'list.' + index + '.CumYield'" :rules="{validator: validrule, trigger: 'blur'}">
                         <Input v-model="item.CumYield"></Input>                           
                      </Form-item>
                    </td>
                    <td >
                      <Form-item :prop="'list.' + index + '.AvgMuYield'" :rules="{validator: validrule, trigger: 'blur'}">                                    
                         {{(item.CumYield != null&&item.CumYield !=''&&item.GrandArea != null&&item.GrandArea != ''&&item.GrandArea*1 !=0)?item.AvgMuYield=((item.CumYield*1)/(item.GrandArea*1)).toFixed(1):item.AvgMuYield=''}}
                      </Form-item>
                    </td>
                    <td >
                      <Form-item :prop="'list.' + index + '.NewArea'" :rules="{validator: validrule, trigger: 'blur'}">
                          <Input v-model="item.NewArea"></Input>                           
                      </Form-item>
                    </td>
                    <td >
                      <Form-item :prop="'list.' + index + '.FOrchard'" :rules="{validator: validrule, trigger: 'blur'}">
                        <Input v-model="item.FOrchard"></Input>                          
                      </Form-item>
                    </td>
                    <td >
                      <Form-item :prop="'list.' + index + '.FTOrchard'" :rules="{validator: validrule, trigger: 'blur'}">
                        <Input v-model="item.FTOrchard"></Input>                         
                      </Form-item>
                    </td>
                    <td >
                      <Form-item :prop="'list.' + index + '.TOrchard'" :rules="{validator: validrule, trigger: 'blur'}">
                        <Input v-model="item.TOrchard"></Input>                        
                      </Form-item>
                    </td>
                    <td>
                      <Form-item :prop="'list.' + index + '.Remark'" >
                        <Input v-model="item.Remark"></Input>
                      </Form-item>
                    </td>                    
                  </tr>
                  <tr>
                    <td style="font-weight:bold;">合计</td>
                    <td>{{tmodel.GrandArea}}</td>
                    <td>{{tmodel.CumYield}}</td>
                    <td>{{tmodel.AvgMuYield}}</td>
                    <td>{{tmodel.NewArea}}</td>
                    <td>{{tmodel.FOrchard}}</td>
                    <td>{{tmodel.FTOrchard}}</td>
                    <td>{{tmodel.TOrchard}}</td>
                    <td>
                      <Form-item>
                        <Input v-model="totalModel.Remark"></Input>
                      </Form-item>
                    </td>
                  </tr>
                  </tbody>
                </table>
                </Form>                         
            <div style="text-align:right;padding-top:10px">
               <Button type="ghost" v-show="rShow" @click="submit()" >上报</Button>
               <Button type="primary" v-show="pShow" @click="save('DataForm')" style="margin-left: 5px">保存</Button>
               <Button type="ghost" @click="ViewShow = false" style="margin-left: 5px">关闭</Button>
          </div>
            <div slot="footer" style="padding-bottom:50px">
                <Alert style="margin-top:5px;text-align:left" banner type="error">
                    填报时间：每年1月10日</br>
                    填报说明: 1.全省范围内从乡（镇）起，逐级全面统计，由县级填报经州（市）审核后上报。
                    <br/> 2.统计面积中不含育苗面积。                    
                    <br/>3. 水果分四个树龄阶段统计，各不互相包含；其中5年以下的，则不包含新植面积；一年生水果不分树龄统计。                    
                    <span slot="desc">
                    </span>
                </Alert>
            </div>
        </Modal>
        <Modal v-model="ReasonShow" :mask-closable="false" width="500"> 
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">未通过原因</span>
            </p>
            <p slot="close">
                <Icon type="close-circled" color="red" size=25></Icon>
            </p>
            <div class="reasonDiv">{{Reason}}</div>
            <p slot="footer"></p>
        </Modal> 
    </div>
</template>
<script>
export default {
  data() {
    const validateData = (rule, value, callback) => {
      var temp = /^[0-9]\d*(\.\d+)?$/;
      if (value != null && value != "") {
        if (temp.test(value) == false) {
          callback(new Error("必须是数字！"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      ReasonShow: false, //是否显示未通过原因Modal
      Reason: "", //未通过原因
      validrule: validateData,
      rShow: false, //是否显示上报按钮
      pShow: false, //是否显示保存按钮
      list: [],
      templist: [],
      totalModel: {
        Remark: ""
      },
      ReportId: "",
      ReportCode: "",
      ViewShow: false, //查看状态
      TableCodeList: this.GetGroupDict("ReportTableName"), //表名称
      CreateYearList: this.GetGroupDict("ReportYear"), //周期
      CycleList: this.GetGroupDict("ReportCycle"), //
      TabTitleList: [], //tab选项卡列表
      CurrentYear: new Date().getFullYear(), //当前年度,
      BtnSaveStatus: false,
      selectTabName: "",
      showType: false, //编辑框弹出状态
      ruleValidate: {
        //验证模型
        TableName: [{ required: true, message: "报表名称不能为空", trigger: "blur" }],
        TableCode: [{ required: true, message: "报表代码不能为空", trigger: "blur" }],
        CreateYear: [{ required: true, message: "年度不能为空", trigger: "blur" }],
        Cycle: [{ required: true, message: "时间周期不能为空", trigger: "blur" }],
        CreateTime: [{ required: true, message: "生成时间不能为空", trigger: "blur" }]
      },
      dataModel: {
        //编辑模型
        Id: 0,
        TableName: "",
        TableCode: "",
        CreateYear: "",
        Cycle: "",
        CreateTime: ""
      },
      //查询模型：根据需求删除不不要查询条件
      searchModel: {
        ReportCode: "FruProSurvey",
        FillInYear: new Date().getFullYear() + "",
        TimesType: "",
        AreaCode: this.GetlocaStorage("fruuserinfo").AreaCode,
        PageNumber: 1,
        PageSize: 20
      },
      pageSizeOpts: [20, 40, 50], //默认分页最大设置
      datas: {}, //table数据对象
      dataIds: [],
      ctx: this, //table数据上下文
      columnsList: [
        //表头对象
        // { type: 'selection', width: 60, align: 'center' },//多选设置
        { title: "报表名称", key: "ReportName" },
        { title: "所属行政区划", key: "AreaCodeName", width: 150 },
        //{ title: "填报年度", key: "FillInYear", width: 150 },
        //{ title: "填报周期", key: "TimesCycle", width: 150 },
        {
          title: "报表状态",
          key: "StatusName",
          width: 150,
          render: (h, params) => {
            switch (params.row.Status * 1) {
              case 0:
                return h(
                  "span",
                  { style: { color: "#ed3f14" } },
                  params.row.StatusName
                );
              case 1:
                return h(
                  "span",
                  { style: { color: "#ff9900" } },
                  params.row.StatusName
                );
              case 2:
                return h(
                  "span",
                  { style: { color: "#993300" } },
                  params.row.StatusName
                );
              case 3:
                return h(
                  "span",
                  { style: { color: "#2d8cf0" } },
                  params.row.StatusName
                );
              case 4:
                return h(
                  "span",
                  { style: { color: "#19be6b" } },
                  params.row.StatusName
                );
              case 5:
                return h(
                  "span",
                  { style: { color: "#80848f" } },
                  params.row.StatusName
                );
              default:
                return h(
                  "span",
                  { style: { color: "#ff9900" } },
                  params.row.StatusName
                );
            }
          }
        },
        // { title: "未通过原因", key: "Opinion" },
        { title: "填报时间", key: "StrUpdateTime", width: 180 },
        {
          title: "操作",
          key: "Id",
          width: 320,
          align: "center",
          render: (h, params) => {
            var reasonStyle = { display: "none" };
            if (params.row.Status * 1 == 0) reasonStyle = {};
            return h("div", [
              h(
                "Upload",
                {
                  props: {
                    //导入成功后响应窗口
                    onSuccess: response => {
                      this.handleSuccess(response);
                    },
                    action: this.GetPostUrl(params.row.Id),
                    size: "small"
                  },
                  style: {
                    float: "left"
                  }
                },
                [
                  h(
                    "Button",
                    {
                      class: { searchButton: true },
                      props: {
                        type: "ghost",
                        size: "small",
                        icon: "ios-cloud-upload-outline",
                        disabled:
                          (params.row.Status == 3 || params.row.Status == 4)||!this.isTime()
                      },
                      style: {
                        marginRight: "5px"
                      }
                    },
                    "导入"
                  )
                ]
              ),
              // h('Button', {
              //     class: {
              //         ieditColor: true
              //     },
              //     props: {
              //         size: 'small',
              //         type: 'ghost',
              //         icon: 'ios-paper-outline'
              //     }, style: {
              //         marginRight: '5px'
              //     }, on: {
              //         click: () => {
              //             this.showInfo(params.row.Id, params.row.ReportCode)
              //         }
              //     }
              // }, '查看'),
              h(
                "Button",
                {
                  class: {
                    ieditColor: true
                  },
                  props: {
                    size: "small",
                    type: "ghost",
                    icon: "ios-compose"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      if (params.row.Status == 2) {
                        this.rShow = true;
                        this.pShow = true;
                      } else if (params.row.Status <= 1) {
                        this.pShow = true;
                      }
                        this.showInfo(params.row.Id, params.row.ReportCode);
                      }
                    }
                },
                params.row.Status <= 2 ? "填报" : "查看"
              ),
              // h('Button', {
              //     class: {
              //         ieditColor: true
              //     },
              //     props: {
              //         size: 'small',
              //         type: 'ghost',
              //         icon: 'ios-trash-outline'
              //     },
              //     style: {
              //         marginRight: '5px'
              //     },
              //     attrs: {
              //         disabled: params.row.Status != 2 ? true : false
              //     },
              //     on: {
              //         click: () => {
              //             this.upReport(params.row.Id)
              //         }
              //     }
              // }, '上报'),
              h(
                "Button",
                {
                  class: { ieditColor: true },
                  props: {
                    type: "ghost",
                    size: "small",
                    icon: "ios-compose"
                  },
                  attrs: {
                    disabled: params.row.Status < 2 ? true : false
                  },
                  style: { marginRight: "5px" },
                  on: {
                    click: () => {
                      this.ExcelDown(params.row.Id);
                    }
                  }
                },
                "导出"
              ),
              h(
                "Button",
                {
                  class: {
                    // ieditColor: true
                  },
                  props: {
                    size: "small",
                    type: "error"
                    //icon: "ios-compose"
                  },
                  style: reasonStyle,
                  on: {
                    click: () => {
                      this.Reason = params.row.Opinion;
                      this.ReasonShow = true;
                    }
                  }
                },
                "未通过原因"
              )
            ]);
          }
        }
      ],
      clientHeight: window.innerHeight - 220 //表格默认高度
    };
  },
  mounted() {
    //table高度计算方法
    const that = this;
    window.onresize = () => {
      return (() => {
        that.clientHeight = window.innerHeight - 220;
      })();
    };
  },
  methods: {
    submit() {
      this.upReport(this.ReportId);
    },
    upReport(id) {
      var self = this;
      if(this.checkData){
      self.$Modal.confirm({
        title: "提示信息",
        content: "<p>是否确认上报？</p>",
        onOk: () => {
          this.rShow = false;
          this.pShow = false;
          var model = new Object();
          model.Id = id;
          model.reportType = "3";
          model.strMsg = "";
          this.$http.post("Report/PostUpStatus", model).then(function(res) {
            if (res.data.status == 1) {
              self.ViewShow = false;
              self.$Notice.success({ title: "已上报！", desc: false });
              self.getPageData();
            } else {
              self.$Modal.error({ title: "提示信息", content: "数据删除失败!!!" });
            }
          });
        }
      });}
    },
    getTab(name) {
      //console.log(name);
      this.selectTabName = name;
    },
    //查看报表
    showInfo(id, reportCode) {
      this.ReportId = id;
      var self = this;
      this.$http
        .get("Report", { params: { id: id, reportCode: reportCode } })
        .then(
          //获取数据编辑项的值
          function(res) {
            switch (res.data.list.status) {
              case 1:
                //self.initTab(self, res.data.list.model);
                self.list = res.data.list.model;
                let temp = [];
                for (var i = 0; i < self.list.length; i++) {
                  var item = self.list[i];
                  if (item.VarietyCode != "sum") {
                    temp.push(item);
                  } else {
                    self.totalModel = item;
                  }
                }
                self.templist = temp;
                self.ViewShow = true;
                break;
              case 0:
                self.$Modal.error({ title: "提示信息", content: "编辑数据加载失败!!!" });
                break;
              case -1:
                self.$Modal.error({ title: "提示信息", content: "编辑数据加载失败!!!" });
                break;
            }
          }
        );
    },
    //获取当前页码
    getPageNumber(pageIndex) {
      this.searchModel.PageNumber = pageIndex;
      this.getPageData();
    },
    //获取当前分页大小
    getPageSize(pageSize) {
      this.searchModel.PageSize = pageSize;
      this.getPageData();
    },
    //获取this.datas: {},//table数据对象
    getPageData() {
      var self = this;
      var user = this.GetlocaStorage("fruuserinfo");
      this.searchModel.AreaCode = user.AreaCode;
      self.$http
        .post("Report/PostPageList", this.searchModel)
        .then(function(res) {
          if (res.data.status === 1) {
            self.datas = res.data;
          } else {
            self.$Modal.error({ title: "提示信息", content: res.data.message });
          }
        });
    },
    //编辑获取对象传入id
    editInfo(id, reportCode) {
      //编辑
      var self = this;
      this.$http
        .get("Report", { params: { id: id, reportCode: reportCode } })
        .then(
          //获取数据编辑项的值
          function(res) {
            switch (res.data.list.status) {
              case 1:
                self.initTab(self, res.data.list.model);
                self.modalShow();
                self.selectTabName = self.TabTitleList[0].SortCode;
                break;
              case 0:
                self.$Modal.error({ title: "提示信息", content: "编辑数据加载失败!!!" });
                break;
              case -1:
                self.$Modal.error({ title: "提示信息", content: "编辑数据加载失败!!!" });
                break;
            }
          }
        );
    },
    initTab(self, datas) {
      self.TabTitleList = [];
      for (var i = 0; i < datas.length; i++) {
        if (!self.checkTab(datas[i].SortCode, self)) {
          var item = new Object();
          item.SortCode = datas[i].SortCode;
          item.SortName = datas[i].SortName;
          item.list = [];
          for (var j = 0; j < datas.length; j++) {
            if (datas[j].SortCode == datas[i].SortCode) {
              if (!self.checkItem(item.list, datas[j].ItemCode)) {
                item.list.push(datas[j]);
              }
            }
          }
          self.TabTitleList.push(item);
        }
      }
      return self.TabTitleList;
    },
    checkTab(SortCode, self) {
      var res = false;
      for (var i = 0; i < self.TabTitleList.length; i++) {
        if (self.TabTitleList[i].SortCode == SortCode) {
          res = true;
        }
      }
      return res;
    },
    checkItem(datas, ItemCode) {
      var res = false;
      for (var i = 0; i < datas.length; i++) {
        if (datas[i].ItemCode == ItemCode) {
          res = true;
        }
      }
      return res;
    },
    //删除对象
    delInfo(id) {
      var self = this;
      self.$Modal.confirm({
        title: "提示信息",
        content: "<p>数据删除后不可恢复，确定要删除？</p>",
        onOk: () => {
          this.$http
            .delete("GenerateLog", { params: { id: id } })
            .then(function(res) {
              if (res.data.status == 1) {
                self.$Notice.success({ title: "删除成功！", desc: false });
                self.getPageData();
              } else {
                self.$Modal.error({ title: "提示信息", content: "数据删除失败!!!" });
              }
            });
        }
      });
    },
    //保存方法
    save(refname) {
      var self = this;
      //var list = this.findItemList(this.selectTabName);
      // var list = [];
      // for (var i = 0; i < this.TabTitleList.length; i++) {

      //     list = list.concat(this.TabTitleList[i].list);

      // }
      // console.log(list)
      //this.Dsum();
      if(this.isTime()){
        let len = this.list.length;
        this.list[len - 1].Remark = this.totalModel.Remark;
        this.$refs[refname].validate(valid => {
        if (valid) {
          this.$http.put("FruProSurvey", this.list).then(function(res) {
            if (res.data.status == 1) {
              self.getPageData(); //读取分页数据
              //self.modalHide();//关闭modal
              //self.ViewShow = false;
              self.rShow = true;
              self.$Notice.success({ title: "保存成功！", desc: false });
            } else {
              self.$Modal.warning({ title: "提示信息", content: "更新失败,请与管理员联系!" });
            }
          });
        } else {
          self.$Modal.error({ title: "提示信息", content: "填入的必须是数字!" });
        }
        });
      }
      else{
        this.$Modal.warning({ title: "提示信息", content: "不在填报时间，无法填报!" });
      }
      
    },
    findItemList(tabname) {
      var list = [];
      for (var i = 0; i < this.TabTitleList.length; i++) {
        if (this.TabTitleList[i].SortCode == tabname) {
          list = this.TabTitleList[i].list;
          break;
        }
      }
      return list;
    },
    //合计
    Dsum() {
      var self = this;
      let model = new Object();
      model.GrandArea = 0;
      model.CumYield = 0;
      model.AvgMuYield = "";
      model.NewArea = 0;
      model.FOrchard = 0;
      model.FTOrchard = 0;
      model.TOrchard = 0;
      for (let i = 0; i < self.list.length; i++) {
        let item = self.list[i];
        if (item.VarietyCode != "sum") {
          if (!item.ParentCode) {
            if (item.GrandArea != null && item.GrandArea != "")
              model.GrandArea += item.GrandArea * 1;
            if (item.CumYield != null && item.CumYield != "")
              model.CumYield += item.CumYield * 1;
            if (item.NewArea != null && item.NewArea != "")
              model.NewArea += item.NewArea * 1;
            if (item.FOrchard != null && item.FOrchard != "")
              model.FOrchard += item.FOrchard * 1;
            if (item.FTOrchard != null && item.FTOrchard != "")
              model.FTOrchard += item.FTOrchard * 1;
            if (item.TOrchard != null && item.TOrchard != "")
              model.TOrchard += item.TOrchard * 1;
          }
        } else {
          self.list[i].GrandArea = model.GrandArea.toFixed(1);
          self.list[i].CumYield = model.CumYield.toFixed(1);
          self.list[i].NewArea = model.NewArea.toFixed(1);
          self.list[i].FOrchard = model.FOrchard.toFixed(1);
          self.list[i].FTOrchard = model.FTOrchard.toFixed(1);
          self.list[i].TOrchard = model.TOrchard.toFixed(1);
          if (model.GrandArea != 0) {
            model.AvgMuYield = (model.CumYield / model.GrandArea).toFixed(1);
          }
          self.list[i].AvgMuYield = model.AvgMuYield;
        }
      }
      model.GrandArea = model.GrandArea.toFixed(1);
      model.CumYield = model.CumYield.toFixed(1);
      model.NewArea = model.NewArea.toFixed(1);
      model.FOrchard = model.FOrchard.toFixed(1);
      model.FTOrchard = model.FTOrchard.toFixed(1);
      model.TOrchard = model.TOrchard.toFixed(1);
      return model;
    },
    //编辑框打开
    modalShow() {
      this.showType = true;
    },
    //编辑框关闭
    modalHide() {
      this.showType = false;
    },
    //取消方法
    cancel() {
      this.showType = false; //关闭modal
      this.TabTitleList = [];
    },
    //重置model
    restModel(modelname) {
      this.$refs[modelname].resetFields(); //重置model
    },
    //全选方法
    selectAll(selection) {
      this.dataIds = selection;
    },
    //checkbox选中方法
    selectSingel(selection, row) {
      this.dataIds = selection;
    },
    //checkbox取消选中方法
    selecChange(selection) {
      this.dataIds = selection;
    },
    //批量删除
    multiSelect() {
      var self = this;
      if (this.dataIds.length !== 0) {
        self.$Modal.confirm({
          title: "提示信息",
          content: "<p>数据删除后不可恢复，确定要删除？</p>",
          onOk: () => {
            var ids = this.getDataIds(this.dataIds);
            this.$http
              .post("GenerateLog/PostBatchDelete", ids)
              .then(function(res) {
                if (res.data.status == 1) {
                  self.dataIds = [];
                  self.$Notice.success({ title: "删除成功！", desc: false });
                  self.getPageData();
                } else {
                  self.$Modal.error({ title: "提示信息", content: "数据删除失败!!!" });
                }
              });
          }
        });
      } else {
        self.$Modal.warning({ title: "提示信息", content: "请选择需要删除的数据!" });
      }
    },
    getDataIds(idList) {
      var ids = [];
      if (idList.length !== 0) {
        for (var i = 0; i < idList.length; i++) {
          ids.push(idList[i].Id);
        }
      }
      return ids;
    },
    TmpDown: function() {
      //模板下载
      window.open(
        this.$http.defaults.baseURL +
          "Report/GetTemplateData?ReportCode=" +
          this.searchModel.ReportCode
      );
    },
    //导入
    GetPostUrl(ReportId) {
      var url =
        this.$http.defaults.baseURL +
        "FruProSurvey/PostImportData?ReportId=" +
        ReportId;
      return url;
    },
    handleSuccess(response) {
      //导入成功反馈事件
      this.getPageData();
      if (response.status == -1) {
        this.$Modal.warning({
          title: "提示信息",
          content: response.message
        });
      } else {
        this.$Notice.success({
          title: "数据导入成功！",
          desc: false
        });
      }
    },
    //导出
    ExcelDown: function(ReportId) {
      var self = this;
      window.open(
        this.$http.defaults.baseURL +
          "FruProSurvey/GetExcelData?ReportId=" +
          ReportId +
          "&&FillInYear=" +
          self.searchModel.FillInYear +
          "&&AreaCode=" +
          self.searchModel.AreaCode
      );
    },
    //数据检测
    checkData(){
     let templist = this.list;
     for(let i = 0;i < templist.length;i++){
       let item  = templist[i];
       let parentModel = new Object();
       parentModel.GrandArea = 0;
       parentModel.CumYield = 0;
       parentModel.NewArea = 0;
       parentModel.FOrchard = 0;
       parentModel.FTOrchard = 0;
       parentModel.TOrchard = 0;  
       parentModel.hasChild = false; 
       for(let j = 0;j < templist.length;j++){
        let sonItem = templist[j];
        if(sonItem.ParentCode == item.VarietyCode){
          parentModel.hasChild = true;
          if(sonItem.GrandArea){
            parentModel.GrandArea += sonItem.GrandArea;
          }
          if(sonItem.CumYield){
            parentModel.CumYield += sonItem.CumYield;
          }
          if(sonItem.NewArea){
            parentModel.NewArea += sonItem.NewArea;
          }
          if(sonItem.FOrchard){
            parentModel.FOrchard += sonItem.FOrchard;
          }
           if(sonItem.FTOrchard){
            parentModel.FTOrchard += sonItem.FTOrchard;
          }
           if(sonItem.TOrchard){
            parentModel.TOrchard += sonItem.TOrchard;
          }
        }
       }
       if(parentModel.hasChild){        
       if(item.GrandArea && parentModel.GrandArea > item.GrandArea){         
         toAlertCheckResult(item.Variety+'的全年累计面积不能小于其子项之和！');
         return false;        
       }
       if(item.CumYield && parentModel.CumYield > item.CumYield){        
         toAlertCheckResult(item.Variety+'的全年累计产量不能小于其子项之和！');
         return false;
       }
       if(item.NewArea && parentModel.NewArea > item.NewArea){        
         toAlertCheckResult(item.Variety+'的本年新建果园面积不能小于其子项之和！');
         return false;
       }
       if(item.FOrchard && parentModel.FOrchard > item.FOrchard){         
        toAlertCheckResult(item.Variety+'的树龄5年以下面积不能小于其子项之和！');
        return false;
       }
       if(item.FTOrchard && parentModel.FTOrchard > item.FTOrchard){
        toAlertCheckResult(item.Variety+'的树龄5-20年面积不能小于其子项之和！');
        return false;
       } 
       if(item.TOrchard && parentModel.TOrchard > item.TOrchard){
        toAlertCheckResult(item.Variety+'的树龄20年以上面积不能小于其子项之和！');
        return false;
       }    
       } 
       if((item.GrandArea - (item.NewArea*1+item.FTOrchard*1+item.FOrchard*1+item.TOrchard*1))<=-1||(item.GrandArea - (item.NewArea*1+item.FTOrchard*1+item.FOrchard*1+item.TOrchard*1))>=1){        
         toAlertCheckResult(item.Variety+'的全年累计面积不等于新植面积、树龄5年以下、5-20年、20年以上面积之和！');
         return false;
       }         
     }     
     return true;
    },
    toAlertCheckResult(message){    
      this.$Modal.warning({
        title:'提示信息',
        content:message
      });
    },
    currentYear() {
      let year = new Date().getFullYear();
      let month = new Date().getMonth();
      if (month > 1) {
        this.searchModel.FillInYear = year.toString();
      } else {
        this.searchModel.FillInYear = (year - 1).toString();
      }
    },
    isTime(){
      let month = new Date().getMonth();  
      let year = new Date().getFullYear(); 
        if(month>2 && month<10&&(this.searchModel.FillInYear==year.toString())){
          return false;
      }
      else{
        return true;
      }
    }
  },
  computed: {
    tmodel: {
      get: function() {
        return this.Dsum();
      }
    }
  },
  //创建Vue页面方法
  created: function() {
    //创业Vue前调用获取this.datas: {},//table数据对象
    this.currentYear();
    this.getPageData();
  },
  watch: {
    //需要监听的在此处新增监听对象
  }
};
</script>
